package com.meal.base.test.DesignMode.state;

/**
 * @program: meal->Switcher
 * @description: 开关类
 * @author: yangzhanghui
 * @create: 2020-04-03 18:16
 **/
public class Switcher {
    //开关的初始状态设置为“关”
    private State state = new Off();

    private Lamp lamp;

    public void lampOn(){
        lamp.on();
    }

    public void lampOff(){
        lamp.off();
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public void switchOn() {
        state.switchOn(this);//这里调用的是当前状态的开方法
    }

    public void switchOff() {
        state.switchOff(this);//这里调用的是当前状态的关方法
    }

    class Lamp{
        void on(){

        }
        void off(){

        }
    }
}